<?php
session_start();
header('Content-type: text/html; charset=utf-8');
require_once"lib/functions.php";
require_once"mysql.php"; 

if ($_SESSION['status']==0){
	header("Location: index.php");
}else if (!($_SESSION['user_id'])){
	header("Location: index.php");
}else{
	if (!empty($_POST))
	{
		$status = (isset($_POST['status'])) ? mysql_real_escape_string($_POST['status']) : '';	
	}
echo'<head>
<title>Web-site</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<div id="wrapper">
  <div id="header"><h1>Web-site</h1></div>
  <div id="navigation"> Navigation Here </div>  
	
	<div id="leftcolumn"><b>
	<p>Контактная информация</p></b>
	<p>Адрес: </p>
	<p>Телефон: </p>';
	//require_once"menu.html";
	require_once"LeftPanel.php";
	echo'</div>
	<div id="content">';
	if (!empty($_GET['type'])){
	if (!empty($_GET['status'])){
		$status=$_GET['status'];
		@$_REQUEST['button2']=true;
	}
	$arr=GetTypeInf($_GET['type']);	
	echo '<h2>'.$arr[0].'</h2>';	
	echo'<form action="ShowMessages.php?type='.$_GET['type'].'" method="post">';
		echo'<p>Выберите, пожалуйста, категорию пользователя:</p>';
		echo'<p><td><select name="status">';
		$result =  mysql_query ("SELECT * FROM status ORDER BY code") or die ("<b>Query failed:</b> " . mysql_error());
		while ($row = mysql_fetch_array($result))
		{ 
			if($row["code"]!=0){
				if($status==$row['code']){
					echo "<option selected value=".$row['code'].">".$row['name']."</option>";
				}else{
					echo "<option value=".$row['code'].">".$row['name']."</option>";
				}				
			}
		}
		echo '</select></td>';			
		echo '<input type="submit" name="button2" value="Выбрать"/></p><br>';			
	echo'</form>';
	if (@$_REQUEST['button2']){
			$_SESSION['but2']=1;
	}
	if($_SESSION['but2']==1){
	$result=GetMessages($_SESSION['user_id'],$status,$_GET['type']);
	if($result){
	if (mysql_num_rows($result)!=0){	
	echo'<table border="1" style="margin=0 auto;" width="50%">
		<tr>
			<td>'.$arr[1].'</td>
			<td>Сообщение</td>
			<td>'.$arr[2].'</td>
		</tr>';
		while ($row = mysql_fetch_array($result))
		{			
			echo'<tr>
				<td>'.$row['name'].'</td>
				<td>'.$row['text'].'</td>
				<td><a href="NewMessage.php?id='.$row[id].'&type='.$_GET['type'].'">'.$arr[2].'</a></td>
			</tr>';
		}
		
	echo'</table>';
	}else{
		echo "<span style='color:red;'>Нет сообщений для данной категории</span>";
	}}
	}
	}
echo'<h4><a href=messages.php>Назад</a></h4>';   
echo'</div>
	<div id="rightcolumn">';
	require_once"RightPanel.php";
echo'</div>	<div id="footer"> This is the Footer </div> 
</div>
</body>
</html>';
}
?>